Skip to contentSkip to conversation

cargo.bbclass: show PACKAGECONFIG_CONFARGS in bbnote

PATCH In review [email protected] 7 participants 19 messages Mar 20, 2025 – May 16, 2025 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 cargo.bbclass: show PACKAGECONFIG_CONFARGS in bbnote

From: Martin Jansa <[email protected]>

* PACKAGECONFIG_CONFARGS was added in:
https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64
but it wasn't added in bbnote above which might lead to confusing errors like I got now:

  NOTE: cargo build -v --frozen --target aarch64-webos-linux-gnu --release --manifest-path=.../git//Cargo.toml
  error: unexpected argument '--cfg' found

  Usage: cargo build --verbose... --frozen --target [<TRIPLE>] --release --manifest-path <PATH>

and was wondering where --cfg came from.

* it was from recipe where we already use:
RUSTFLAGS:append = " ${PACKAGECONFIG_CONFARGS}"
it will be difficult to use PACKAGECONFIG for RUSTFLAGS and prevent them to be used here for cargo as well, what about the recipes which need them to explicitly append them to CARGO_BUILD_FLAGS ?

---
 meta/classes-recipe/cargo.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes-recipe/cargo.bbclass +1 -1
index 461d100dd9..2dd28e95d3 100644
@@ -47,7 +47,7 @@ oe_cargo_build () {
 	export RUSTFLAGS="${RUSTFLAGS}"
 	bbnote "Using rust targets from ${RUST_TARGET_PATH}"
 	bbnote "cargo = $(which ${CARGO})"
-	bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
+	bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} ${PACKAGECONFIG_CONFARGS} $@"
 	"${CARGO}" build ${CARGO_BUILD_FLAGS} ${PACKAGECONFIG_CONFARGS} "$@"
 }
 
#1 lore raw

PATCH 2/2 cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

From: Martin Jansa <[email protected]>

* some recipes might be using PACKAGECONFIG_CONFARGS as:
RUSTFLAGS:append = " ${PACKAGECONFIG_CONFARGS}"

and then it's difficult to prevent the same args being used here for cargo call as well add intermedate variable CARGO_BUILD_FLAGS_PACKAGECONFIG
which could be set to empty in the recipe to avoid that.

* alternatively we can just revert:
https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64
and let each recipe decide how it wants to use PACKAGECONFIG_CONFARGS

---
 meta/classes-recipe/cargo.bbclass | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
meta/classes-recipe/cargo.bbclass +4 -2
index 2dd28e95d3..63e550f5d0 100644
@@ -43,12 +43,14 @@ CARGO_BUILD_FLAGS = "-v --frozen --target ${RUST_HOST_SYS} ${BUILD_MODE} --manif
 # change if CARGO_BUILD_FLAGS changes.
 BUILD_DIR = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}"
 CARGO_TARGET_SUBDIR = "${RUST_HOST_SYS}/${BUILD_DIR}"
+CARGO_BUILD_FLAGS_PACKAGECONFIG = ?= "${PACKAGECONFIG_CONFARGS}"
+CARGO_BUILD_FLAGS:append = " ${CARGO_BUILD_FLAGS_PACKAGECONFIG}"
 oe_cargo_build () {
 	export RUSTFLAGS="${RUSTFLAGS}"
 	bbnote "Using rust targets from ${RUST_TARGET_PATH}"
 	bbnote "cargo = $(which ${CARGO})"
-	bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} ${PACKAGECONFIG_CONFARGS} $@"
-	"${CARGO}" build ${CARGO_BUILD_FLAGS} ${PACKAGECONFIG_CONFARGS} "$@"
+	bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
+	"${CARGO}" build ${CARGO_BUILD_FLAGS} "$@"
 }
 
 do_compile[progress] = "outof:\s+(\d+)/(\d+)"

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

This 2nd one was supposed to be sent only as RFC, but I forgot to update subject sorry.

And this version also has a typo "= ?=", will send v2 if we want to do something like this (reverting the
https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64
is imho better as it doesn't respect the original author from
https://patchwork.yoctoproject.org/project/oe-core/patch/[email protected]/
and with CARGO_BUILD_FLAGS_PACKAGECONFIG it's imho more confusing than useful as the default)

Quoted 50 lines · Martin Jansa via lists.openembedded.org

From: Martin Jansa <[email protected]>

* some recipes might be using PACKAGECONFIG_CONFARGS as:
RUSTFLAGS:append = " ${PACKAGECONFIG_CONFARGS}"

and then it's difficult to prevent the same args being used here for cargo call as well add intermedate variable CARGO_BUILD_FLAGS_PACKAGECONFIG
which could be set to empty in the recipe to avoid that.

* alternatively we can just revert:
https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64
and let each recipe decide how it wants to use PACKAGECONFIG_CONFARGS

---
 meta/classes-recipe/cargo.bbclass | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
meta/classes-recipe/cargo.bbclass +4 -3
index 2dd28e95d3..63e550f5d0 100644
@@ -43,12 +43,14 @@ CARGO_BUILD_FLAGS = "-v --frozen --target ${RUST_HOST_SYS} ${BUILD_MODE} --manif
 # change if CARGO_BUILD_FLAGS changes.
 BUILD_DIR = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}"
 CARGO_TARGET_SUBDIR = "${RUST_HOST_SYS}/${BUILD_DIR}"
+CARGO_BUILD_FLAGS_PACKAGECONFIG = ?= "${PACKAGECONFIG_CONFARGS}"
+CARGO_BUILD_FLAGS:append = " ${CARGO_BUILD_FLAGS_PACKAGECONFIG}"
 oe_cargo_build () {
        export RUSTFLAGS="${RUSTFLAGS}"
        bbnote "Using rust targets from ${RUST_TARGET_PATH}"
        bbnote "cargo = $(which ${CARGO})"
-       bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} ${PACKAGECONFIG_CONFARGS} $@"
-       "${CARGO}" build ${CARGO_BUILD_FLAGS} ${PACKAGECONFIG_CONFARGS} "$@"
+       bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
+       "${CARGO}" build ${CARGO_BUILD_FLAGS} "$@"
 }
 
 do_compile[progress] = "outof:\s+(\d+)/(\d+)"
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#213418): https://lists.openembedded.org/g/openembedded-core/message/213418
Mute This Topic: https://lists.openembedded.org/mt/111812382/3617156
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#4 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Quoted 10 lines · Martin Jansa via lists.openembedded.org

This 2nd one was supposed to be sent only as RFC, but I forgot to update subject sorry.

And this version also has a typo "= ?=", will send v2 if we want to do something like this (reverting the
https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64
is imho better as it doesn't respect the original author from
https://patchwork.yoctoproject.org/project/oe-core/patch/[email protected]/
and with CARGO_BUILD_FLAGS_PACKAGECONFIG it's imho more confusing than useful as the default)

I have a strong preference for not carrying things like this. If there are existing recipes that break, we should just fix them and move on rather than letting the past dictate the future IMO.

I'm trying really hard to simplify things where we can.

Cheers,

Richard

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Quoted 15 lines · Richard Purdie via lists.openembedded.org
Quoted 12 lines · Martin Jansa via lists.openembedded.org

This 2nd one was supposed to be sent only as RFC, but I forgot to update subject sorry.

And this version also has a typo "= ?=", will send v2 if we want to do
something like this (reverting the
https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64
is imho better as it doesn't respect the original author from
https://patchwork.yoctoproject.org/project/oe-core/patch/[email protected]/
and with CARGO_BUILD_FLAGS_PACKAGECONFIG it's imho more confusing than
useful as the default)

Quoted 6 lines

I have a strong preference for not carrying things like this. If there
are existing recipes that break, we should just fix them and move on rather than letting the past dictate the future IMO.

I'm trying really hard to simplify things where we can.

Martin pointed out I was misreading things.

If there are recipes using packageconfig in RUSTFLAGS then this will break that. We probably do need to revert as I really don't like the alternative variable mess. It does mean recipes will specifically need to add the flags to the carbo build parameters but that is the lesser of several evils IMO.

Cheers,

Richard

#7 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Quoted 25 lines · Richard Purdie
Quoted 15 lines · Richard Purdie via lists.openembedded.org
Quoted 12 lines · Martin Jansa via lists.openembedded.org

This 2nd one was supposed to be sent only as RFC, but I forgot to update subject sorry.

And this version also has a typo "= ?=", will send v2 if we want to do
something like this (reverting the
https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64
is imho better as it doesn't respect the original author from
https://patchwork.yoctoproject.org/project/oe-core/patch/[email protected]/
and with CARGO_BUILD_FLAGS_PACKAGECONFIG it's imho more confusing than
useful as the default)

Quoted 6 lines

I have a strong preference for not carrying things like this. If there
are existing recipes that break, we should just fix them and move on rather than letting the past dictate the future IMO.

I'm trying really hard to simplify things where we can.

Quoted 7 lines

Martin pointed out I was misreading things.

If there are recipes using packageconfig in RUSTFLAGS then this will break that. We probably do need to revert as I really don't like the alternative variable mess. It does mean recipes will specifically need to add the flags to the carbo build parameters but that is the lesser of several evils IMO.

Agreed about the revert being lesser evil.

I know very little about rust/cargo, so it's also possible that we're using rust/cargo wrong and there is a better way to achieve conditional compilation with flags passed to cargo not by RUSTFLAGS.

I've checked the recipe where we're using:
RUSTFLAGS:append = " ${PACKAGECONFIG_CONFARGS}"
and it's public as:
https://github.com/webosose/meta-webosose/blob/master/meta-webos/recipes-multimedia/gstreamer/gstreamer1.0-plugins-webosrs.bb

With the RUSTFLAGS then being used as PACKAGECONFIG[unifieddecodebin] = '--cfg feature=\"unifieddecodebin\"' in the recipe and in code e.g.
https://github.com/webosose/gst-plugins-webos/blob/%40rust/gst-rs/unifiedbin/src/lib.rs
as:
#[cfg(feature = "unifieddecodebin")]
...

Will send revert unless Jean-Pierre or Bartosz have better idea how to deal with this.

Cheers,

#8 lore raw

Re: [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Hello all,

First good catch Martin!
Regarding cargo usage it's better to use feature flag (--feature) as RUSTFLAGS is passed at each compiler invocation (you risk to have a conflict with another feature in other crate dependency compilation and enable it without wanting that).

I'm really sorry if I credited the author incorrectly, I'd made the same fix before looking to see if it had already been proposed.

I think both approaches are respectable, but the revert will keep Rust recipes apart forever, which may not be the most unified IMHO.

#9 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

In reply to Martin Jansa

In my recipe I use it as:

CARGO_BUILD_FLAGS:append = " ${PACKAGECONFIG_CONFARGS}" The recipe is public here:
https://github.com/Jarsop/meta-zenoh/blob/master/meta-zenoh/recipes-connectivity/zenoh/zenoh_git.bb

Best regards

Le jeu. 20 mars 2025 à 18:36, Martin Jansa <[email protected]> a écrit :

Quoted 63 lines
Quoted 5 lines · Richard Purdie
Quoted 2 lines · Richard Purdie via lists.openembedded.org

On Thu, 2025-03-20 at 17:59 +0100, Martin Jansa via lists.openembedded.org wrote:

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

This 2nd one was supposed to be sent only as RFC, but I forgot to update subject sorry.

And this version also has a typo "= ?=", will send v2 if we want to do
something like this (reverting the

https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

is imho better as it doesn't respect the original author from

https://patchwork.yoctoproject.org/project/oe-core/patch/[email protected]/

Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

and with CARGO_BUILD_FLAGS_PACKAGECONFIG it's imho more confusing than
useful as the default)

I have a strong preference for not carrying things like this. If there
are existing recipes that break, we should just fix them and move on rather than letting the past dictate the future IMO.

I'm trying really hard to simplify things where we can.

Quoted 7 lines

Martin pointed out I was misreading things.

If there are recipes using packageconfig in RUSTFLAGS then this will break that. We probably do need to revert as I really don't like the alternative variable mess. It does mean recipes will specifically need to add the flags to the carbo build parameters but that is the lesser of several evils IMO.

Agreed about the revert being lesser evil.

I know very little about rust/cargo, so it's also possible that we're using rust/cargo wrong and there is a better way to achieve conditional compilation with flags passed to cargo not by RUSTFLAGS.

I've checked the recipe where we're using:
RUSTFLAGS:append = " ${PACKAGECONFIG_CONFARGS}"
and it's public as:

https://github.com/webosose/meta-webosose/blob/master/meta-webos/recipes-multimedia/gstreamer/gstreamer1.0-plugins-webosrs.bb

With the RUSTFLAGS then being used as PACKAGECONFIG[unifieddecodebin] = '--cfg feature=\"unifieddecodebin\"' in the recipe and in code e.g.

https://github.com/webosose/gst-plugins-webos/blob/%40rust/gst-rs/unifiedbin/src/lib.rs
as:
#[cfg(feature = "unifieddecodebin")]
...

Will send revert unless Jean-Pierre or Bartosz have better idea how to deal with this.

Cheers,

#10 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

I basically agree with Jean-Pierre. Optional features should not be set via RUSTFLAGS at all, rather Cargo.toml in the source tree should be extended to include them as described here:

https://doc.rust-lang.org/cargo/reference/features.html

So gst-plugins-webos should be fixed, then the recipe for it, then I'd say we should reconsider this patch. If a recipe inherits cargo, then it is expected to pass configuration settings via cargo, otherwise it needs to use its own custom class.

Alex

Quoted 78 lines · Jean-Pierre Geslin via lists.openembedded.org

In my recipe I use it as:

CARGO_BUILD_FLAGS:append = " ${PACKAGECONFIG_CONFARGS}"
The recipe is public here: https://github.com/Jarsop/meta-zenoh/blob/master/meta-zenoh/recipes-connectivity/zenoh/zenoh_git.bb

Best regards

Quoted 55 lines · Martin Jansa
Quoted 25 lines · Richard Purdie
Quoted 15 lines · Richard Purdie via lists.openembedded.org
Quoted 12 lines · Martin Jansa via lists.openembedded.org

This 2nd one was supposed to be sent only as RFC, but I forgot to update subject sorry.

And this version also has a typo "= ?=", will send v2 if we want to do
something like this (reverting the
https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64
is imho better as it doesn't respect the original author from
https://patchwork.yoctoproject.org/project/oe-core/patch/[email protected]/
and with CARGO_BUILD_FLAGS_PACKAGECONFIG it's imho more confusing than
useful as the default)

Quoted 6 lines

I have a strong preference for not carrying things like this. If there
are existing recipes that break, we should just fix them and move on rather than letting the past dictate the future IMO.

I'm trying really hard to simplify things where we can.

Quoted 7 lines

Martin pointed out I was misreading things.

If there are recipes using packageconfig in RUSTFLAGS then this will break that. We probably do need to revert as I really don't like the alternative variable mess. It does mean recipes will specifically need to add the flags to the carbo build parameters but that is the lesser of several evils IMO.

Agreed about the revert being lesser evil.

I know very little about rust/cargo, so it's also possible that we're using rust/cargo wrong and there is a better way to achieve conditional compilation with flags passed to cargo not by RUSTFLAGS.

I've checked the recipe where we're using:
RUSTFLAGS:append = " ${PACKAGECONFIG_CONFARGS}"
and it's public as:
https://github.com/webosose/meta-webosose/blob/master/meta-webos/recipes-multimedia/gstreamer/gstreamer1.0-plugins-webosrs.bb

With the RUSTFLAGS then being used as PACKAGECONFIG[unifieddecodebin] = '--cfg feature=\"unifieddecodebin\"' in the recipe and in code e.g.
https://github.com/webosose/gst-plugins-webos/blob/%40rust/gst-rs/unifiedbin/src/lib.rs
as:
#[cfg(feature = "unifieddecodebin")]
...

Quoted 4 lines

Will send revert unless Jean-Pierre or Bartosz have better idea how to deal with this.

Cheers,

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#213425): https://lists.openembedded.org/g/openembedded-core/message/213425
Mute This Topic: https://lists.openembedded.org/mt/111812482/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#11 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

I had to patch Cargo.toml in gst-plugins-webos to define all possible options in [features] to avoid "error: the package 'gst-plugin-unifiedbin' does not contain these features:
unifieddecodebin, .." and then I was able to change our PACKAGECONFIG to pass them with --features instead of --cfg feature and use them with cargo as the previous patch did. I didn't verify it in runtime yet, but it passed the build.

If that's the recommended option, then I'm fine with that and only 1/2 should be merged and not this 2/2 nor the revert RP sent earlier today.

Regards,

Quoted 95 lines · Alexander Kanavin

I basically agree with Jean-Pierre. Optional features should not be set via RUSTFLAGS at all, rather Cargo.toml in the source tree should be extended to include them as described here:

https://doc.rust-lang.org/cargo/reference/features.html

So gst-plugins-webos should be fixed, then the recipe for it, then I'd say we should reconsider this patch. If a recipe inherits cargo, then it is expected to pass configuration settings via cargo, otherwise it needs to use its own custom class.

Alex

Quoted 78 lines · Jean-Pierre Geslin via lists.openembedded.org

In my recipe I use it as:

CARGO_BUILD_FLAGS:append = " ${PACKAGECONFIG_CONFARGS}"
The recipe is public here: https://github.com/Jarsop/meta-zenoh/blob/master/meta-zenoh/recipes-connectivity/zenoh/zenoh_git.bb

Best regards

Quoted 55 lines · Martin Jansa
Quoted 25 lines · Richard Purdie
Quoted 15 lines · Richard Purdie via lists.openembedded.org
Quoted 12 lines · Martin Jansa via lists.openembedded.org

This 2nd one was supposed to be sent only as RFC, but I forgot to update subject sorry.

And this version also has a typo "= ?=", will send v2 if we want to do
something like this (reverting the
https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64
is imho better as it doesn't respect the original author from
https://patchwork.yoctoproject.org/project/oe-core/patch/[email protected]/
and with CARGO_BUILD_FLAGS_PACKAGECONFIG it's imho more confusing than
useful as the default)

Quoted 6 lines

I have a strong preference for not carrying things like this. If there
are existing recipes that break, we should just fix them and move on rather than letting the past dictate the future IMO.

I'm trying really hard to simplify things where we can.

Quoted 7 lines

Martin pointed out I was misreading things.

If there are recipes using packageconfig in RUSTFLAGS then this will break that. We probably do need to revert as I really don't like the alternative variable mess. It does mean recipes will specifically need to add the flags to the carbo build parameters but that is the lesser of several evils IMO.

Agreed about the revert being lesser evil.

I know very little about rust/cargo, so it's also possible that we're using rust/cargo wrong and there is a better way to achieve conditional compilation with flags passed to cargo not by RUSTFLAGS.

I've checked the recipe where we're using:
RUSTFLAGS:append = " ${PACKAGECONFIG_CONFARGS}"
and it's public as:
https://github.com/webosose/meta-webosose/blob/master/meta-webos/recipes-multimedia/gstreamer/gstreamer1.0-plugins-webosrs.bb

With the RUSTFLAGS then being used as PACKAGECONFIG[unifieddecodebin] = '--cfg feature=\"unifieddecodebin\"' in the recipe and in code e.g.
https://github.com/webosose/gst-plugins-webos/blob/%40rust/gst-rs/unifiedbin/src/lib.rs
as:
#[cfg(feature = "unifieddecodebin")]
...

Quoted 4 lines

Will send revert unless Jean-Pierre or Bartosz have better idea how to deal with this.

Cheers,

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#213425): https://lists.openembedded.org/g/openembedded-core/message/213425
Mute This Topic: https://lists.openembedded.org/mt/111812482/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#12 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Quoted 8 lines · Martin Jansa

I had to patch Cargo.toml in gst-plugins-webos to define all possible options in [features] to avoid "error: the package 'gst-plugin-unifiedbin' does not contain these features:
unifieddecodebin, .." and then I was able to change our PACKAGECONFIG to pass them with --features instead of --cfg feature and use them with cargo as the previous patch did. I didn't verify it in runtime yet, but it passed the build.

Quoted 4 lines

If that's the recommended option, then I'm fine with that and only 1/2
should be merged and not this 2/2 nor the revert RP sent earlier today.

If we all agree then I can drop the revert and add 1/2 back and merge that...

Cheers,

Richard

#13 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

In reply to Martin Jansa

Hello,

In meta-security,  suricata is  mixed C and Rust  build  so I use PACKAGECONFIG for the autoconf part and now the RUST portion is complaining about configuration options it does not understand.

Rust error:
error: unexpected argument '--with-libcap_ng-includes' found

reverting the commits fixes my issue.

BR,
Armin

Quoted 106 lines · Martin Jansa via lists.openembedded.org

I had to patch Cargo.toml in gst-plugins-webos to define all possible options in [features] to avoid "error: the packagekkkk 'gst-plugin-unifiedbin' does not contain these features:
unifieddecodebin, .." and then I was able to change our PACKAGECONFIG to pass them with --features instead of --cfg feature and use them with cargo as the previous patch did. I didn't verify it in runtime yet, but it passed the build.

If that's the recommended option, then I'm fine with that and only 1/2 should be merged and not this 2/2 nor the revert RP sent earlier today.

Regards,

Quoted 90 lines · Alexander Kanavin

I basically agree with Jean-Pierre. Optional features should not be set via RUSTFLAGS at all, rather Cargo.toml in the source tree should be extended to include them as described here:

https://doc.rust-lang.org/cargo/reference/features.html

So gst-plugins-webos should be fixed, then the recipe for it, then I'd say we should reconsider this patch. If a recipe inherits cargo, then it is expected to pass configuration settings via cargo, otherwise it needs to use its own custom class.

Alex

Quoted 74 lines · Jean-Pierre Geslin via lists.openembedded.org

In my recipe I use it as:

CARGO_BUILD_FLAGS:append = " ${PACKAGECONFIG_CONFARGS}"
The recipe is public here: https://github.com/Jarsop/meta-zenoh/blob/master/meta-zenoh/recipes-connectivity/zenoh/zenoh_git.bb

Best regards

Quoted 50 lines · Martin Jansa
Quoted 21 lines · Richard Purdie
Quoted 19 lines · Richard Purdie via lists.openembedded.org
Quoted 12 lines · Martin Jansa via lists.openembedded.org

This 2nd one was supposed to be sent only as RFC, but I forgot to update subject sorry.

And this version also has a typo "= ?=", will send v2 if we want to do
something like this (reverting the
https://git.openembedded.org/openembedded-core/commit/?id=16745b20452de60ae2474433cc1a2fb1ed9f6a64
is imho better as it doesn't respect the original author from
https://patchwork.yoctoproject.org/project/oe-core/patch/[email protected]/
and with CARGO_BUILD_FLAGS_PACKAGECONFIG it's imho more confusing than
useful as the default)

I have a strong preference for not carrying things like this. If there
are existing recipes that break, we should just fix them and move on rather than letting the past dictate the future IMO.

Quoted 8 lines
Quoted 1 line

I'm trying really hard to simplify things where we can.

Martin pointed out I was misreading things.

If there are recipes using packageconfig in RUSTFLAGS then this will break that. We probably do need to revert as I really don't like the alternative variable mess. It does mean recipes will specifically need to add the flags to the carbo build parameters but that is the lesser of several evils IMO.

Agreed about the revert being lesser evil.

I know very little about rust/cargo, so it's also possible that we're using rust/cargo wrong and there is a better way to achieve conditional compilation with flags passed to cargo not by RUSTFLAGS.

I've checked the recipe where we're using:
RUSTFLAGS:append = " ${PACKAGECONFIG_CONFARGS}"
and it's public as:
https://github.com/webosose/meta-webosose/blob/master/meta-webos/recipes-multimedia/gstreamer/gstreamer1.0-plugins-webosrs.bb

With the RUSTFLAGS then being used as PACKAGECONFIG[unifieddecodebin] = '--cfg feature=\"unifieddecodebin\"' in the recipe and in code e.g.
https://github.com/webosose/gst-plugins-webos/blob/%40rust/gst-rs/unifiedbin/src/lib.rs
as:
#[cfg(feature = "unifieddecodebin")]
...

Quoted 4 lines

Will send revert unless Jean-Pierre or Bartosz have better idea how to deal with this.

Cheers,

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#213571): https://lists.openembedded.org/g/openembedded-core/message/213571
Mute This Topic: https://lists.openembedded.org/mt/111812482/3616698
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#14 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Quoted 8 lines · On Mon, 31 Mar 2025 at 18:18, akuster808 <[email protected]> wrote:

In meta-security, suricata is mixed C and Rust build so I use PACKAGECONFIG for the autoconf part and now the RUST portion is complaining about configuration options it does not understand.

Rust error:
error: unexpected argument '--with-libcap_ng-includes' found

reverting the commits fixes my issue.

The recipe inherits both autotools and cargo, and then overwrites configure(), compile() and install() with its own versions that manually run the rust bits:

https://git.yoctoproject.org/meta-security/tree/recipes-ids/suricata/suricata_7.0.0.bb?h=master

It needs to be fixed to use cargo_common class, similar to librsvg. Inheriting cargo class means cargo (and not something else) is used as the top build system.

Alex

#15 lore raw

Re: [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Hello,

This change also breaks recipes where cargo is used as the top build system but PACKAGECONFIG_CONFARGS should not be included into cargo parameters. See, for example:
https://git.yoctoproject.org/meta-security/tree/meta-parsec/recipes-parsec/parsec-service/parsec-service_1.4.1.bb

What is the reason for this change? If a recipe needs to use PACKAGECONFIG for cargo parameters then the recipe can update CARGO_BUILD_FLAGS accordingly. With this change I don't have an option to not include  PACKAGECONFIG_CONFARGS into parameters. Can it be reverted?

Anton

#16 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Quoted 5 lines · Anton Antonov via lists.openembedded.org

This change also breaks recipes where cargo is used as the top build system but PACKAGECONFIG_CONFARGS should not be included into cargo parameters. See, for example:
https://git.yoctoproject.org/meta-security/tree/meta-parsec/recipes-parsec/parsec-service/parsec-service_1.4.1.bb

What is the reason for this change? If a recipe needs to use PACKAGECONFIG for cargo parameters then the recipe can update CARGO_BUILD_FLAGS accordingly.
With this change I don't have an option to not include PACKAGECONFIG_CONFARGS into parameters. Can it be reverted?

The reason is that the standard usage of PACKAGECONFIG definitions is to define and directly supply arguments to the top level build tool. This is how autotools, cmake, meson and other classes work, and this simply makes cargo class consistent them. If you need to supply these arguments some other way, then you can follow for example mesa.inc and define empty PACKAGECONFIGS:

PACKAGECONFIG[amd] = ""
PACKAGECONFIG[svga] = ""
PACKAGECONFIG[virgl] = ""

And then use them to form a custom variable, which you can use as you see fit:

GALLIUMDRIVERS:append = "${@bb.utils.contains('PACKAGECONFIG', 'gallium-llvm', '${GALLIUMDRIVERS_LLVM}', '', d)}" GALLIUMDRIVERS:append = "${@bb.utils.contains('PACKAGECONFIG', 'amd', ',r600', '', d)}"
GALLIUMDRIVERS:append = "${@bb.utils.contains('PACKAGECONFIG', 'virgl', ',virgl', '', d)}"

Alex

#17 lore raw

Re: [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Quoted 9 lines · Alexander Kanavin

If you need to supply these
arguments some other way, then you can follow for example mesa.inc and define empty PACKAGECONFIGS:

PACKAGECONFIG[amd] = ""
PACKAGECONFIG[svga] = ""
PACKAGECONFIG[virgl] = ""

Quoted 7 lines

And then use them to form a custom variable, which you can use as you see fit:

GALLIUMDRIVERS:append = "${@bb.utils.contains('PACKAGECONFIG', 'gallium-llvm', '${GALLIUMDRIVERS_LLVM}', '', d)}" GALLIUMDRIVERS:append = "${@bb.utils.contains('PACKAGECONFIG', 'amd', ',r600', '', d)}"

I think using PACKAGECONFIG to define cargo features list is a normal use-case in rust based recipes. With this change is not easily achievable because ${PACKAGECONFIG_CONFARGS} is unquoted in cargo.bbclass and we can't use it with CARGO_BUILD_FLAGS += " --features" if there are more than one feature. So, if the change is not going to be reverted then we realistically have two options - either complicate the recipes with a lot of conditions like you suggest or just add a comment that oe_cargo_build() is broken in cargo.bbclass and define our own do_compile()

Anton

#18 lore raw

Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Can you put —features directly into packageconfig definitions? Does cargo accept multiple —features flags?

Alex

Quoted 41 lines · Anton Antonov via lists.openembedded.org

On Fri, May 16, 2025 at 08:55 AM, Alexander Kanavin wrote:

If you need to supply these
arguments some other way, then you can follow for example mesa.inc and define empty PACKAGECONFIGS:

PACKAGECONFIG[amd] = ""
PACKAGECONFIG[svga] = ""
PACKAGECONFIG[virgl] = ""

And then use them to form a custom variable, which you can use as you see fit:

GALLIUMDRIVERS:append = "${@bb.utils.contains('PACKAGECONFIG', 'gallium-llvm', '${GALLIUMDRIVERS_LLVM}', '', d)}" GALLIUMDRIVERS:append = "${@bb.utils.contains('PACKAGECONFIG', 'amd', ',r600', '', d)}"

I think using PACKAGECONFIG to define cargo features list is a normal
use-case in rust based recipes. With this change is not easily achievable because ${PACKAGECONFIG_CONFARGS} is unquoted in cargo.bbclass and we can't use it with CARGO_BUILD_FLAGS += " --features" if there are more than one feature.
So, if the change is not going to be reverted then we realistically have
two options - either complicate the recipes with a lot of conditions like you suggest or just add a comment that oe_cargo_build() is broken in cargo.bbclass and define our own do_compile()

Anton

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#216759):
https://lists.openembedded.org/g/openembedded-core/message/216759
Mute This Topic: https://lists.openembedded.org/mt/111812482/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#19 lore raw

RE: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Yes, you can have multiple --features statements in cargo command line.
We use multiple packageconfigs in our cargo recipes successfully which then looks something like:
PACKAGECONFIG ?= “feature1 feature2”
PACKAGECONFIG[feature1] = "--features feature1,"
PACKAGECONFIG[feature2] = "--features feature2,"
PACKAGECONFIG[feature3] = "--features feature3,"

Peter

From: [email protected] <[email protected]> On Behalf Of Alexander Kanavin via lists.openembedded.org
Sent: Friday, May 16, 2025 19:19
To: [email protected]
Cc: [email protected]
Subject: Re: [OE-core] [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

Can you put —features directly into packageconfig definitions? Does cargo accept multiple —features flags?

Alex

On Fri 16. May 2025 at 18.39, Anton Antonov via lists.openembedded.org<http://lists.openembedded.org> <[email protected]<mailto:[email protected]>> wrote:
On Fri, May 16, 2025 at 08:55 AM, Alexander Kanavin wrote:
If you need to supply these
arguments some other way, then you can follow for example mesa.inc and
define empty PACKAGECONFIGS:

PACKAGECONFIG[amd] = ""
PACKAGECONFIG[svga] = ""
PACKAGECONFIG[virgl] = ""

And then use them to form a custom variable, which you can use as you see fit:

GALLIUMDRIVERS:append = "${@bb.utils.contains('PACKAGECONFIG',
'gallium-llvm', '${GALLIUMDRIVERS_LLVM}', '', d)}<mailto:$%[email protected]('PACKAGECONFIG',%0b'gallium-llvm',%20'$%7bGALLIUMDRIVERS_LLVM%7d',%20'',%20d)%7d>"
GALLIUMDRIVERS:append = "${@bb.utils.contains('PACKAGECONFIG', 'amd',
',r600', '', d)}<mailto:$%[email protected]('PACKAGECONFIG',%20'amd',%0b',r600',%20'',%20d)%7d>"
I think using PACKAGECONFIG to define cargo features list is a normal use-case in rust based recipes. With this change is not easily achievable because ${PACKAGECONFIG_CONFARGS} is unquoted in cargo.bbclass and we can't use it with CARGO_BUILD_FLAGS += " --features" if there are more than one feature. So, if the change is not going to be reverted then we realistically have two options - either complicate the recipes with a lot of conditions like you suggest or just add a comment that oe_cargo_build() is broken in cargo.bbclass and define our own do_compile()
Anton

#20 lore raw

Re: [PATCH 2/2] cargo.bbclass: allow to avoid appending PACKAGECONFIG_CONFARGS

In reply to Alexander Kanavin
Quoted 3 lines · Alexander Kanavin

Can you put —features directly into packageconfig definitions? Does cargo accept multiple —features flags?

Oh, yes it works. Thanks. The only small problem is I can't use comma-separated features in  PACKAGECONFIG because it itself is comma-separated. So I have to add --features before each feature in the same line. It doesn't look bad if I use -F instead of --features though:

PACKAGECONFIG ??= "PKCS11 MBED-CRYPTO"
have_TPM = "${@bb.utils.contains('DISTRO_FEATURES', 'tpm2', 'TPM', '', d)}" PACKAGECONFIG:append = " ${@bb.utils.contains('BBFILE_COLLECTIONS', 'tpm-layer', '${have_TPM}', '', d)}"

PACKAGECONFIG[ALL] = "-F all-providers -F cryptoki/generate-bindings -F tss-esapi/generate-bindings,,tpm2-tss libts,tpm2-tss libtss2-tcti-device libts" PACKAGECONFIG[TPM] = "-F tpm-provider -F tss-esapi/generate-bindings,,tpm2-tss,tpm2-tss libtss2-tcti-device" PACKAGECONFIG[PKCS11] = "-F pkcs11-provider -F cryptoki/generate-bindings,"
PACKAGECONFIG[MBED-CRYPTO] = "-F mbed-crypto-provider,"
PACKAGECONFIG[CRYPTOAUTHLIB] = "-F cryptoauthlib-provider,"
PACKAGECONFIG[TS] = "-F trusted-service-provider,,libts,libts"

Anton